#
#  $Id$
#

@SET_MAKE@
srcdir = @srcdir@
VPATH = @srcdir@
RTEMS_ROOT = @top_srcdir@
PROJECT_ROOT = @PROJECT_ROOT@
RTEMS_GAS_CODE16 = @RTEMS_GAS_CODE16@

PGMS=${ARCH}/start.o ${ARCH}/start16.bin

# C source names, if any, go here -- minus the .c
C_PIECES=
C_FILES=$(C_PIECES:%=%.c)
C_O_FILES=$(C_PIECES:%=${ARCH}/%.o)

H_FILES=

# Assembly source names, if any, go here -- minus the .s
S_PIECES=start16 start
S_FILES=$(S_PIECES:%=%.s)
S_O_FILES=$(S_FILES:%.s=${ARCH}/%.o)

SRCS=$(C_FILES) $(H_FILES) $(S_FILES)
OBJS=$(C_O_FILES) $(S_O_FILES)

include $(RTEMS_ROOT)/make/custom/$(RTEMS_BSP).cfg
include $(RTEMS_ROOT)/make/leaf.cfg

#
# (OPTIONAL) Add local stuff here using +=
#

ifeq ($(RTEMS_GAS_CODE16),yes)
DEFINES  += -DNEW_GAS
endif
CPPFLAGS +=
CFLAGS   +=

LD_PATHS  +=
LD_LIBS   +=
LDFLAGS   +=

#
# Add your list of files to delete here.  The config files
#  already know how to delete some stuff, so you may want
#  to just run 'make clean' first to see what gets missed.
#  'make clobber' already includes 'make clean'
#

CLEAN_ADDITIONS +=
CLOBBER_ADDITIONS +=

all:	${ARCH} $(SRCS) $(OBJS) $(PGMS)
	$(INSTALL_VARIANT) -m 555 ${PGMS} ${PROJECT_RELEASE}/lib

# Install the program(s), appending _g or _p as appropriate.
# for include files, just use $(INSTALL)

LINKCMDS=$(srcdir)/../startup/linkcmds

${ARCH}/start16.o: start16.s
	sed -e 's/\/\/.*$$//' < $< | $(CPP) $(ASMFLAGS) -I. -I$(srcdir) \
	  -DASM -DHEADERADDR=$(HEADERADDR) - > $*.i
	$(AS) $(ASFLAGS) -o $@ $*.i

${ARCH}/start16.bin: ${ARCH}/start16.o
	$(LD) -N -T $(LINKCMDS) -Ttext $(START16ADDR) -e start16 -nostdlib \
	  --oformat=elf32-i386 -o $(basename $@).obj $(basename $@).o
	$(OBJCOPY) -O binary $(basename $@).obj $@
